<?php
namespace app\index\controller;

use app\common\controller\Front;

class Topic extends Front
{
    // 活动专题
    public function index()
    {
        $id = $this->request->param('id/d', 0);
        // 文章内容
        $topic = \Fields::getById('special_topic', $id);
        foreach ($topic as $key => $val) {
            $result = preg_match('/(detail|background|image)_(\d+)/', $key, $matches);
            if ($result) {
                switch ($matches[1]) {
                    case 'detail': 
                        $topic['detail'][$matches[2]] = \Fields::parse_option_to_3d($val, "block", "\r\n", '|');
                        break;
                    case 'background': 
                        $topic['background'][$matches[2]] = $val;
                        break;
                    case 'image':
                        $topic['image'][$matches[2]] = $val; 
                        break;
                }
                unset($topic[$key]);
            }
        }
        $this->view->assign('topic', $topic);
        $this->assign('_page', [
            'title' => '爱员工官网',
            'name' => $topic['name']
        ]);
        return $this->view->fetch();
    }
}
